<input type="hidden" id="new_tweet_status" value="<?php echo $this->session->flashdata('new_tweet_status'); ?>" />
<input type="hidden" id="update_tweet_status" value="<?php echo $this->session->flashdata('update_tweet_status'); ?>" />
<input type="hidden" id="tweet_tweet_id" value="<?php echo $this->session->flashdata('tweet_tweet_id'); ?>" />
<input type="hidden" id="tweet_tweet_hash" value="<?php echo $this->session->flashdata('tweet_tweet_hash'); ?>" />
<script type="text/javascript">
  $(document).ready(function() {
    load_new_replies(true);
    $('#tweet_reply').wysihtml5();
    update_likes_count();
    var tweet_tweet_id = $.trim($('#tweet_tweet_id').val());
    var tweet_tweet_hash = $.trim($('#tweet_tweet_hash').val());
    if ((tweet_tweet_id) && (tweet_tweet_hash)) {
      send_notification('new_tweet', tweet_tweet_id, tweet_tweet_hash);
    }
    var new_tweet_status = $.trim($('#new_tweet_status').val());
    if (new_tweet_status == 1) {
      toastr.success('Successfully created tweet !');
    }
    var update_tweet_status = $.trim($('#update_tweet_status').val());
    if (update_tweet_status == 1) {
      toastr.success('Successfully updated tweet !');
    }
  });
</script>
<div class="page" style="min-height: 500px;">
  <div class="page-container">
    <div class="container">
      <div class="row">
        <div class="span12 header">
          <div class="btn-group pull-right"><a href="<?php echo base_url('tweet/create'); ?>" class="btn pull-right">Create Tweet</a></div>
          <h4>Tweet</h4>
        </div>
        <div class="span3">
          <div class="filters">
            <span class="pull-right"><?php echo $tweet_extras_data['tweet_owner_dispaly_name']; ?></span>
            <label for="cb3">Tweet by</label>
            <span class="pull-right" id="total_replies_count_sub"><?php echo $tweet_extras_data['tweet_total_replies_count']; ?></span>
            <label for="cb3">Total replies</label>
            <span class="pull-right" id="my_replies_count_sub"><?php echo $tweet_extras_data['tweet_my_replies_count']; ?></span>
            <label for="cb3">Your replies</label>
            <h5>Repliers (<span id="repliers_count"><?php echo (int) count($tweet_users_data); ?></span>)</h5>
            <div id="repliers_data">
              <?php if (!empty($tweet_users_data)) { ?>
                <?php foreach ($tweet_users_data as $tweet_user) { ?>
                  <span class="pull-right"><?php echo $tweet_user['user_replies_count']; ?></span>
                  <label for="cb5">
                    <?php if (is_online($tweet_user['user_id'])) { ?>
                      <img src="<?php echo site_url('assets/img/online_button_tiny.png'); ?>" title="Online"/>
                    <?php } else { ?>
                      <img src="<?php echo site_url('assets/img/offline_button_tiny.png'); ?>" title="Offline"/>
                    <?php } ?>
                    <a title="<?php echo '@' . $tweet_user['user_name']; ?>" style="text-decoration: none; color: #333;" href="<?php echo base_url('profile/' . $tweet_user['user_name']); ?>"><?php echo $tweet_user['user_display_name']; ?></a>
                  </label>
                <?php } ?>
              <?php } else { ?>
                No Repliers !
              <?php } ?>
            </div>
          </div>

          <div class="filters">
            <h5>Viewers (<span id="viewers_count"><?php echo (int) count($tweet_viewers); ?></span>)</h5>
            <div id="viewers_data">
              <?php if (!empty($tweet_viewers)) { ?>
                <?php foreach ($tweet_viewers as $viewer) { ?>
                  <a id="tweet_viewer_<?php echo $viewer['user_id']; ?>" title="<?php echo '@' . $viewer['user_name']; ?>" href="<?php echo base_url('profile/' . $viewer['user_name']); ?>">
                    <img class="thumbnail pull-left" style="max-width: 32px; max-height: 32px; margin: 4px;" src="<?php echo base_url('assets/photos/' . $viewer['user_image']); ?>" alt="Image"/>
                  </a>
                <?php } ?>
              <?php } else { ?>
                <a id="tweet_viewer_<?php echo $this->current_user['user_id']; ?>" title="<?php echo '@' . $this->current_user['user_name']; ?>" href="<?php echo base_url('profile/' . $this->current_user['user_name']); ?>">
                  <img class="thumbnail pull-left" style="max-width: 32px; max-height: 32px; margin: 4px;" src="<?php echo base_url('assets/photos/' . $this->current_user['user_image']); ?>" alt="Image"/>
                </a>
              <?php } ?>
            </div>
          </div>

        </div>
        <div class="span9">
          <div class="messages">
            <h4 class="header" style="word-break: break-all;"><?php echo $tweet_data['tweet_subject']; ?></h4>
            <div class="message">
              <a href="<?php echo base_url('profile/' . $tweet_data['user_name']); ?>"><img title="<?php echo $tweet_data['user_display_name']; ?>" src="<?php echo base_url('assets/photos/' . $tweet_data['user_image']); ?>" class="img-rounded pull-left" style="max-height: 60px; max-width: 60px;"/></a>
              <div class="message-body">
                <p class="pull-right">
                  <?php $post_id = 'T' . $tweet_data['tweet_id']; ?>
                  <a id="<?php echo $post_id; ?>" style="text-decoration: none; cursor: pointer; color: salmon;" href="#<?php echo $post_id; ?>">&nbsp;&nbsp;#<?php echo $post_id; ?></a>
                </p>
                <p class="pull-right">&nbsp;<?php echo date('d - M - Y', strtotime($tweet_data['tweet_date'])); ?></p>
                <p class="pull-right"><a title="Ignore post | <?php echo get_ignore_count('tweet', $tweet_data['tweet_id']); ?> ignores !" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="ignore_post_<?php echo $tweet_data['tweet_id']; ?>" onclick="return ignore_post('tweet', '<?php echo $tweet_data['tweet_id']; ?>');"><i class="icon-large icon-flag"></i></a>&nbsp;</p>
                <?php if (($this->current_user['user_id'] == $tweet_data['user_id']) || ($this->is_admin)) { ?>
                  <a title="Delete tweet" style="color: #f8b9b7; float: right; margin-right: 10px; text-decoration: none;" onclick="return confirm_action('Delete tweet ?');" href="<?php echo base_url('tweet/delete/' . $tweet_data['tweet_id']); ?>"><i class="icon-large icon-trash"></i></a>
                  <a title="Update tweet" style="color: skyblue; float: right; margin-right: 10px; text-decoration: none;" href="<?php echo base_url('tweet/update/' . $tweet_data['tweet_id']); ?>"><i class="icon-large icon-edit"></i></a>
                <?php } ?>
                <?php if (!empty($tweet_follow_data)) { ?>
                  <a id="follow_button" onclick="return follow_tweet('<?php echo $tweet_data['tweet_id']; ?>', '0');" style="text-decoration: none; color: purple; float: right; margin-right: 10px; cursor: pointer;" title="Unfollow tweet"><i class="icon-large icon-star"></i></a>
                <?php } else { ?>
                  <a id="follow_button" onclick="return follow_tweet('<?php echo $tweet_data['tweet_id']; ?>', '1');" style="text-decoration: none; color: purple; float: right; margin-right: 10px; cursor: pointer;" title="Follow tweet"><i class="icon-large icon-star-empty"></i></a>
                <?php } ?>
                <span style="float: right; margin-right: 10px;">
                  <?php $get_user_like_status = get_user_like_status('tweet', $tweet_data['tweet_id']); ?>
                  <?php if ($get_user_like_status['status'] == 'yes') { ?>
                    <a title="Unlike" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="like_button_tweet_<?php echo $tweet_data['tweet_id']; ?>" onclick="return do_like_action('tweet', '<?php echo $tweet_data['tweet_id']; ?>', '0');"><i class="icon-large icon-thumbs-down"></i></a>
                  <?php } else { ?>
                    <a title="Like" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="like_button_tweet_<?php echo $tweet_data['tweet_id']; ?>" onclick="return do_like_action('tweet', '<?php echo $tweet_data['tweet_id']; ?>', '1');"><i class="icon-large icon-thumbs-up"></i></a>
                  <?php } ?>
                </span>
                <a class="update_like_count" title="Show users who like this" onclick="return show_liked_users('tweet', '<?php echo $tweet_data['tweet_id']; ?>');" style="text-decoration: none; color: #777; float: right; margin-right: 10px; cursor: pointer;" id="like_count_tweet_<?php echo $tweet_data['tweet_id']; ?>"><?php echo $get_user_like_status['total_count']; ?> Likes</a>
                <h5>
                  <?php echo $tweet_data['user_display_name']; ?>
                  &nbsp;
                  <span style="color: #777; font-size: smaller;">(@<?php echo $tweet_data['user_name']; ?>)</span>
                  &nbsp;
                  <?php if (is_online($tweet_data['user_id'])) { ?>
                    <img src="<?php echo site_url('assets/img/online_button_tiny.png'); ?>" title="Online"/>
                  <?php } else { ?>
                    <img src="<?php echo site_url('assets/img/offline_button_tiny.png'); ?>" title="Offline"/>
                  <?php } ?>
                </h5>
                <p id="tweet_message" style="word-break: normal;"><?php echo nl2br(parse_smileys($tweet_data['tweet_message'], base_url('assets/smileys'))); ?></p>
              </div>
            </div>
            <div class="stats">
              <div class="row-fluid">
                <div class="span3">
                  <div class="stat info">
                    <h2 id="total_replies_count_main"><?php echo $tweet_extras_data['tweet_total_replies_count']; ?></h2>
                    <h6>Replies</h6>
                  </div>
                </div>
                <div class="span3">
                  <div class="stat danger">
                    <h2 id="likes_count_main"><?php echo $get_user_like_status['total_count']; ?></h2>
                    <h6>Likes</h6>
                  </div>
                </div>
                <div class="span3">
                  <div class="stat warning">
                    <h2 id="followers_count_main"><?php echo $tweet_followers_count; ?></h2>
                    <h6>Followers</h6>
                  </div>
                </div>
                <div class="span3">
                  <div class="stat inverse">
                    <h2><?php echo days_ago($tweet_data['tweet_date']) + 1; ?></h2>
                    <h6>Days</h6>
                  </div>
                </div>
              </div>
            </div>
            <div class="message">
              <b>Reply</b>
              <img id="loading_anim_blue" style="margin-left: 5px; margin-top: -5px; display: none;" src="<?php echo base_url('assets/img/loading_animation.gif'); ?>"/>
            </div>
            <div id="reply_tweet">
              <a href="<?php echo base_url('profile/' . $this->current_user['user_name']); ?>"><img title="<?php echo $this->current_user['user_display_name']; ?>" src="<?php echo base_url('assets/photos/' . $this->current_user['user_image']); ?>" class="img-rounded pull-left" style="max-height: 60px; max-width: 60px;"/></a>
              <div class="message-body">
                <input type="hidden" name="csrf_token" value="<?php echo set_csrf_token(); ?>"/>
                <textarea id="tweet_reply" name="tweet_reply" placeholder="Enter your reply" style="resize: vertical;"></textarea>
                <a class="badge badge-info" id="malayalam_button" style="float: right; cursor: pointer; margin-right: 15px; text-decoration: none;" onclick="return write_malayalam('tweet_reply');">malaylam</a>
                <input id="post_reply_button" type="button" class="btn" value="Reply" onclick="return post_tweet_reply('<?php echo $tweet_data['tweet_id']; ?>');"/>
                <?php $tweet_reply_form_message = $this->session->flashdata('tweet_reply_form_message'); ?>
                <?php if ($tweet_reply_form_message == 'Success :)') { ?>
                  <label style="float: right; margin-right: 15px; color: yellowgreen;"><?php echo $tweet_reply_form_message; ?></label>
                <?php } else { ?>
                  <label style="float: right; margin-right: 15px; color: tomato;"><?php echo $tweet_reply_form_message; ?></label>
                <?php } ?>
              </div>
            </div>
            <div style="height: 25px;"></div>
            <div id="new_tweets">
              <div id="show_replies">
                <ul class="nav nav-tabs">
                  <li <?php if ($reply_sort == 1) { ?> class="active" <?php } ?> >
                    <a id="sort" href="<?php echo base_url('tweet/' . $tweet_data['tweet_id'] . '?sort=1#sort'); ?>" title="Sory by new replies">New Replies</a>
                  </li>
                  <li <?php if ($reply_sort == 2) { ?> class="active" <?php } ?> >
                    <a id="sort" href="<?php echo base_url('tweet/' . $tweet_data['tweet_id'] . '?sort=2#sort'); ?>" title="Sory by top replies">Top Replies</a>
                  </li>
                </ul>
              </div>
            </div>
            <?php if (!empty($tweet_reply_data)) { ?>
              <?php foreach ($tweet_reply_data as $tweet_reply) { ?>
                <?php $post_id = 'R' . $tweet_reply['tweet_reply_id']; ?>
                <div class="message" id="reply_<?php echo $tweet_reply['tweet_reply_id']; ?>">
                  <a href="<?php echo base_url('profile/' . $tweet_reply['user_name']); ?>"><img title="<?php echo $tweet_reply['user_display_name']; ?>" src="<?php echo base_url('assets/photos/' . $tweet_reply['user_image']); ?>" class="img-rounded pull-left" style="max-height: 60px; max-width: 60px;"/></a>
                  <div class="message-body">
                    <p class="pull-right">
                      <a id="<?php echo $post_id; ?>" style="text-decoration: none; cursor: pointer; color: salmon;" href="#<?php echo $post_id; ?>">&nbsp;&nbsp;<?php echo $post_id; ?></a>
                    </p>
                    <p class="pull-right">&nbsp;(<?php echo time_ago($tweet_reply['tweet_reply_date']); ?> ago)</p>
                    <p class="pull-right"><a title="Ignore post | <?php echo get_ignore_count('reply', $tweet_reply['tweet_reply_id']); ?> ignores !" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="ignore_reply_<?php echo $tweet_reply['tweet_reply_id']; ?>" onclick="return ignore_post('reply', '<?php echo $tweet_reply['tweet_reply_id']; ?>');"><i class="icon-large icon-flag"></i></a>&nbsp;</p>
                    <?php if (($this->current_user['user_id'] == $tweet_reply['user_id']) || ($this->is_admin)) { ?>
                      <a onclick="return delete_tweet_reply('<?php echo $tweet_reply['tweet_reply_id'] ?>');" style="text-decoration: none; cursor: pointer; float: right; margin-right: 10px;" title="Delete reply"><i class="icon-large icon-trash"></i></a>
                    <?php } ?>
                    <?php if ($tweet_reply['user_id'] != $this->current_user['user_id']) { ?>
                      <a onclick="return reply_to_user('tweet_reply', '<?php echo $tweet_reply['user_name']; ?>', '#<?php echo $post_id; ?>');" style="text-decoration: none; cursor: pointer; float: right; margin-right: 10px;" title="Reply to this user"><i class="icon-large icon-retweet"></i></a>
                    <?php } ?>
                    <span style="float: right; margin-right: 10px;">
                      <?php $get_user_like_status = get_user_like_status('reply', $tweet_reply['tweet_reply_id']); ?>
                      <?php if ($get_user_like_status['status'] == 'yes') { ?>
                        <a title="Unlike" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="like_button_reply_<?php echo $tweet_reply['tweet_reply_id']; ?>" onclick="return do_like_action('reply', '<?php echo $tweet_reply['tweet_reply_id']; ?>', '0');"><i class="icon-large icon-thumbs-down"></i></a>
                      <?php } else { ?>
                        <a title="Like" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="like_button_reply_<?php echo $tweet_reply['tweet_reply_id']; ?>" onclick="return do_like_action('reply', '<?php echo $tweet_reply['tweet_reply_id']; ?>', '1');"><i class="icon-large icon-thumbs-up"></i></a>
                      <?php } ?>
                    </span>
                    <a class="update_like_count" title="Show users who like this" onclick="return show_liked_users('reply', '<?php echo $tweet_reply['tweet_reply_id']; ?>');" style="text-decoration: none; color: #777; float: right; margin-right: 10px; cursor: pointer;" id="like_count_reply_<?php echo $tweet_reply['tweet_reply_id']; ?>"><?php echo $get_user_like_status['total_count']; ?> Likes</a>
                    <h5>
                      <?php echo $tweet_reply['user_display_name']; ?>
                      &nbsp;
                      <span style="color: #777; font-size: smaller;">(@<?php echo $tweet_reply['user_name']; ?>)</span>
                      &nbsp;
                      <?php if (is_online($tweet_reply['user_id'])) { ?>
                        <img src="<?php echo site_url('assets/img/online_button_tiny.png'); ?>" title="Online"/>
                      <?php } else { ?>
                        <img src="<?php echo site_url('assets/img/offline_button_tiny.png'); ?>" title="Offline"/>
                      <?php } ?>
                    </h5>
                    <p style="word-break: normal;"><?php echo nl2br(parse_smileys($tweet_reply['tweet_reply_message'], base_url('assets/smileys'))); ?></p>
                  </div>
                </div>
              <?php } ?>
              <div id="old_tweet_replies"></div>
              <div id="load_more"></div>
              <?php if (isset($tweet_extras_data['tweet_total_replies_count'])) { ?>
                <?php if ($tweet_extras_data['tweet_total_replies_count'] > $reply_limit) { ?> 
                  <a id="load_more_buttons" style="text-decoration: none; cursor: pointer; float: right; color: black" onclick="return load_old_replies();" title="Load more replies">
                    <img id="loading_animation" src="<?php echo base_url('assets/img/loading_black.gif'); ?>" style="display: none;"/>&nbsp;<b>more</b>&nbsp;<i class="icon-large icon-chevron-down"></i>
                  </a>
                <?php } ?>
              <?php } ?>
            <?php } else { ?>
              <div class="alert alert-error" id="no_replies">
                <strong>No replies !</strong>
              </div>
            <?php } ?>
            <input type="hidden" id="tweet_id" value="<?php echo $tweet_data['tweet_id']; ?>" />
            <input type="hidden" id="last_reply_id" value="<?php echo $last_reply_id; ?>" />
            <input type="hidden" id="replies_sort_by" value="<?php echo $reply_sort; ?>" />
            <?php if ($reply_sort == 2) { ?>
              <input type="hidden" id="last_loaded_reply_id" value="10" />
            <?php } else { ?>
              <input type="hidden" id="last_loaded_reply_id" value="<?php echo $last_loaded_reply_id; ?>" />
            <?php } ?>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>